<include file="Common:header" />

<body>

	<div class="panel admin-panel">
		<div class="panel-head"><strong>栏目列表</strong>
		</div>
		<div class="padding border-bottom">
			<!--<input type="button" class="button button-small checkall" name="checkall" checkfor="id" value="全选" />-->
			<a class="button button-small border-green" href="{:U('Lmkj/Content/showAddContent')}">添加顶级栏目</a>

			<!--<input type="button" class="button button-small border-yellow" value="批量删除" />-->
		</div>
		<table class="table table-hover">
			<tr cid=0>
				<th width="45"></th>
				<th width="45"></th>
				<th width="45">id</th>
				<th width="*">名称</th>
				<th width="200">时间</th>
				<th width="300">操作</th>
			</tr>
			<foreach name="data" item="v">
				<tr cid='{$v.cid}' cateId='{$v.category_id}' isEnd="{$v._end}" state="{$v.state}">
					<td>
						<input type="checkbox" name="id" value="{$v.category_id}" />
					</td>
					<td width="30"><a href="javascript:;" class="button button-little jiahao">+</a>
					</td>
					<td>{$v.category_id}</td>
					<td>{$v._name}</td>
					<td>{$v.cate_time|date="y-m-d",###}</td>
					<td>
						<a class="button border-green button-little" href="{:U('Lmkj/Content/showAddSonContent',array('id'=>$v['category_id']))}">添加子栏目</a>
						<a class="button border-blue button-little" href="{:U('Lmkj/Content/showAddContent',array('id'=>$v['category_id']))}">修改</a>
						<a class="button border-yellow button-little del " href="javascript:;" data-id="{$v.category_id}">删除</a>
					</td>
				</tr>
			</foreach>

		</table>

	</div>
	<!--成功-->
	<div class="alert alert-green successInfo" style="width: 300px;display: none;position: absolute;">
		<span class="close rotate-hover"></span><strong>恭喜：</strong>操作成功。</div>
	<!--失败-->
	<div class="alert alert-yellow errorInfo" style="width: 300px;display: none;position: absolute;" ><span class="close rotate-hover  " ></span><strong>注意：</strong>操作失败，未知原因/先删除子栏目。</div>
	<!--加载-->
	<div class="alert alert-blue loadInfo" style="width: 300px;display: none;position: absolute;" ><span class="close rotate-hover " ></span>努力加载中...</div>

	
	<link type="text/css" rel="stylesheet" href="__PUBLIC__/css/showBo.css" />
	<script type="text/javascript" src="__PUBLIC__/js/showBo.js"></script>
	<script type="text/javascript">
		var APP = "__APP__";
		$(function() {
				// pid !=0  的全部隐藏	
				$('tr[cid != 0]').hide();
				$(".jiahao").each(function() {
						var _this = $(this)[0];
						_this.c = 0;
						state = $(this).parents('tr').attr('state');
						if (state == 'open') {
							$(this).removeAttr('class').html('');
						}
						$(this).click(function() {
							if (_this.c == 0) {
								$(this).html('-');
								//						让cid == cateId 显示
								_this.cateId = $(this).parents('tr').attr('cateId');
								$("tr[cid =" + _this.cateId + "]").show();
								_this.c = 1;
							} else {
								$(this).html('+');
								_this.cateId = $(this).parents('tr').attr('cateId');
								$("tr[cid =" + _this.cateId + "]").hide();
								_this.c = 0;
							}
						})
					})
					//删除
				$(".del").click(function() {
					var a = Showbo.Msg.confirm('您确定删除这条记录吗？');
					var id = $(this).attr('data-id');
					del(id);
				})
			})
			/**
			 * 设置到中间
			 */

		function setMiddle(cls) {
			//获得当前设置到中间
			var bWidth = $("body").width();
			var bHeight = $("body").height();
			//获得这个成功的消息
			var sWidth = $(cls).width();
			var sHeight = $(cls).height();
			var diffWidth = (bWidth - sWidth) / 2;
			var diffHeight = (bHeight - sHeight) / 2;
			$(cls).css({
				'top': diffHeight,
				'left': diffWidth,
				'zIndex': 1000
			}).show();
		}
		//删除
		function del(id){
			$("#dvMsgBtns .btn").eq(0).click(function(){
				$.ajax({
					type: "post",
					url: APP + "/Lmkj/Content/delCate",
					data: {
						'id': id
					},
					dataType: 'json',
					beforeSend: function() {
						setMiddle(".loadInfo");
					},
					success: function(data) {
						$(".loadInfo").hide();
						if (data) {
							setMiddle(".successInfo");
							window.location.reload();
						} else {
							setMiddle(".errorInfo");
						}
					}
				});
			})
		}
		
	</script>
</body>

</html>